1 package org.apache.maven.surefire.junitcore.pc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.concurrent.CancellationException;
23 import java.util.concurrent.ConcurrentLinkedQueue;
24 import java.util.concurrent.ExecutionException;
25 import java.util.concurrent.ExecutorService;
26 import java.util.concurrent.Future;
27
28
29
30
31
32
33
34
35 final class SharedThreadPoolStrategy
36 extends AbstractThreadPoolStrategy
37 {
38 SharedThreadPoolStrategy( ExecutorService threadPool )
39 {
40 super( threadPool, new ConcurrentLinkedQueue<Future<?>>() );
41 }
42
43 @Override
44 public boolean hasSharedThreadPool()
45 {
46 return true;
47 }
48
49 @Override
50 public boolean finished()
51 throws InterruptedException
52 {
53 boolean wasRunningAll = canSchedule();
54 for ( Future<?> futureResult : getFutureResults() )
55 {
56 try
57 {
58 futureResult.get();
59 }
60 catch ( InterruptedException e )
61 {
62
63
64 wasRunningAll = false;
65 }
66 catch ( ExecutionException e )
67 {
68
69 }
70 catch ( CancellationException e )
71 {
72
73 }
74 }
75 disable();
76 return wasRunningAll;
77 }
78
79 @Override
80 protected final boolean stop()
81 {
82 return stop( false );
83 }
84
85 @Override
86 protected final boolean stopNow()
87 {
88 return stop( true );
89 }
90
91 private boolean stop( boolean interrupt )
92 {
93 final boolean wasRunning = canSchedule();
94 for ( Future<?> futureResult : getFutureResults() )
95 {
96 futureResult.cancel( interrupt );
97 }
98 disable();
99 return wasRunning;
100 }
101 }